import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
  UseInterceptors,
} from '@nestjs/common';
import { AuthInterceptor } from 'src/base/auth-interceptor';
import { YixiantongService } from 'src/yixiantong/yixiantong.service';
import { YixiantongCitiesService } from './yixiantong-cities.service';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { YixiantongCitiesDto } from './yixiantong-cities.dto';

@ApiTags('一线通 - 城市信息管理')
@Controller('/api/yixiantong-cities')
@UseInterceptors(new AuthInterceptor())
export class YixiantongCitiesController {
  constructor(
    private readonly yixiantongService: YixiantongService,
    private readonly yixiantongCitiesService: YixiantongCitiesService,
  ) {}

  @ApiOperation({ summary: '全量获取城市信息' })
  @Get('/all-cities')
  getAllCities() {
    return this.yixiantongService.getFields();
  }

  @Get('/list')
  @ApiOperation({ summary: '分页获取城市列表' })
  getCityList(
    @Query('page') page: number,
    @Query('pageSize') pageSize: number,
    @Query('keyword') keyword: string,
  ) {
    return this.yixiantongCitiesService.getList(page ?? 1, pageSize ?? 10, keyword ?? '');
  }

  @Get('/:id')
  @ApiOperation({ summary: '根据 id 获取城市详情' })
  getCityDetail(@Param('id') id: string) {
    return this.yixiantongCitiesService.getCityDetail(Number(id));
  }

  @Post('/')
  @ApiOperation({ summary: '新增城市信息', description: '添加唯一标识的城市信息' })
  createCity(@Body() formData: YixiantongCitiesDto) {
    return this.yixiantongCitiesService.createCity(formData);
  }

  @Put('/:id')
  @ApiOperation({ summary: '更新城市信息', description: '更新唯一标识的城市信息' })
  updateCity(@Param('id') id: string, @Body() formData: YixiantongCitiesDto) {
    return this.yixiantongCitiesService.updateCity(Number(id), formData);
  }

  @Delete('/:id')
  @ApiOperation({ summary: '删除城市信息', description: '删除唯一标识的城市信息' })
  deleteCity(@Param('id') id: string) {
    return this.yixiantongCitiesService.deleteCity(Number(id));
  }
}
